package com.datn.DataAccess;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.datn.beans.FavouriteBean;
import com.datn.utils.places.ItemFavouriteViewGroup;
import com.datn.utils.places.ItemPlaceViewGroup;
import com.datn.utils.places.Place;

public class ListFavouriteAdapter extends ArrayAdapter<FavouriteBean>{
	private ArrayList<FavouriteBean> listFavourite;
	private int resourse;
	private Context mContext;

	public ListFavouriteAdapter(Context context, int textViewResourceId,
			ArrayList<FavouriteBean> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		mContext=context;
		listFavourite=objects;
		this.resourse=textViewResourceId;
	}


	@Override
	public FavouriteBean getItem(int position) {
		// TODO Auto-generated method stub
		return listFavourite.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}


	@Override
	public int getPosition(FavouriteBean item) {
		// TODO Auto-generated method stub
		return listFavourite.indexOf(item);
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View workView = convertView;

		if (workView == null) {
			workView = new ItemFavouriteViewGroup(getContext());
		}

		//Edit from here
		final FavouriteBean favourite = listFavourite.get(position);

		if (favourite != null) {
			ImageView tvImagePlace = ((ItemFavouriteViewGroup) workView).tvImageFavourite;
			TextView tvName = ((ItemFavouriteViewGroup) workView).tvNameFavourite;
			TextView tvAddress = ((ItemFavouriteViewGroup) workView).tvAddressFavourite;
			
			/*if (favourite.getImage()!=null)
				tvImagePlace.setImageBitmap(favourite.getImage());*/
			tvName.setText(favourite.getNameplace());
			tvAddress.setText(String.valueOf(favourite.getAddress()));

		}        
		return workView;
	}


	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}

}
